package cn.plushine.service;


import cn.plushine.mapper.BaseSupplierMapper;
import cn.plushine.pojo.Supplier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 供应商信息
 */
@Service
public class BaseSupplierServiceImpl implements BaseSupplierService {

    @Autowired
    BaseSupplierMapper baseSupplierMapper;

    // 获取供应商信息列表
    @Override
    public List<Supplier> get(String input) {
        // 无论有无数据，直接返回即可
        return baseSupplierMapper.get(input);
    }

    // 添加供应商信息
    @Override
    public int add(Supplier supplier) throws Exception {
        int addDB = baseSupplierMapper.add(supplier);
        if (addDB != 0) {
            return addDB;
        }
        throw new Exception("添加供应商信息失败！");
    }

    // 修改供应商信息失败
    @Override
    public int modify(Supplier supplier) throws Exception {
        int modifyDB = baseSupplierMapper.modify(supplier);
        if (modifyDB != 0) {
            return modifyDB;
        }
        throw new Exception("修改供应商信息失败");
    }

    @Override
    public int delete(int id) throws Exception {
        int modifyDB = baseSupplierMapper.delete(id);
        if (modifyDB != 0) {
            return modifyDB;
        }
        throw new Exception("删除供应商信息失败");
    }
}
